<template>
  <div>
<h2>用户借款</h2>
<table class="table table-bordered">
  <tr>
    <td>借款名称</td>
    <td>{{ state.BI_Name }}</td>
  </tr>
  <tr>
    <td>借款金额</td>
    <td><input type="text" v-model="UB_Money"></td>
  </tr>
  <tr>
    <td></td>
    <td><input type="button" value="借款" class="btn btn-success" @click="borrow"></td>
  </tr>
</table>
  </div>
</template>

<script setup lang="ts">

import {reactive,toRefs,onMounted} from 'vue'
import axios from 'axios'
import {useRouter,useRoute} from 'vue-router'
const router=useRouter()
const route=useRoute()

const data:any=reactive({
  state:{
    BI_Name:''
  },
  UB_Money:''
})

let {state,UB_Money} =toRefs(data)

onMounted(()=>{
  show()
})

const show=()=>{
  axios({
    url:'/api/Borrow/GetBorrowUser',
    method:'get',
    params:{
      ubid:route.query.id,
      BI_Name:state.value.BI_Name
    }
  }).then(res=>{
    console.log(res)
    state.value=res.data.data[0]
  }).catch(err=>{
    console.log(err)
  })
}



const borrow=()=>{
  axios({
    url:'/api/Borrow/PostBorrow',
    method:'post',
    data:{
      BI_Id:route.query.id,
      UB_Money:UB_Money.value
    }
  }).then(res=>{
    console.log(res)
    if(res.data.data>0){
      alert("借款成功")
      router.push('/userborrow')
    }else{
      alert("借款失败")
    }
  }).catch(err=>{
    console.log(err)
  })
}



</script>

<style scoped>

</style>